package demo03;

import org.junit.Test;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class ScheduleExectorServiceDemo01 {


    public static void main(String a[]){
        //1.获取一个具备延迟执行任务的线程池对象
        ScheduledExecutorService es= Executors.newScheduledThreadPool(3);
        //创建多个任务对象,提交任务，延迟2秒执行
        for (int i=1;i<=10;i++){
        es.schedule(new MyRunable(i),2, TimeUnit.SECONDS);}
        System.out.println("over");
    }

}
class MyRunable implements Runnable{

    private int id;

    public MyRunable (int id){
        this.id=id;
    }


    @Override
    public void run() {
        String name=Thread.currentThread().getName();
        System.out.println(name+"执行了"+id);
    }
}
